package com.lianxi.jdbc;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by Administrator on 2018/4/26 0026.
 */
public class SqlServerDBHelper {
    private static BasicDataSource ds = new BasicDataSource();

    static {
        String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        // 卫健委1
//        String url = "jdbc:sqlserver://192.168.77.100:1433;databaseName=wjwmhweb";
//        String user = "weijianwei";
//        String pwd = "dffwv1V231";
        // 卫健委2
//        String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=wjwmhweb";
//        String user = "weijianwei";
//        String pwd = "dffwv1V231";
        // 商务厅
//        String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=SWTDB";
//        String user = "SWTDB";
//        String pwd = "335B725FTXcid";
        /*String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=SWTDB1";
        String user = "SWTDB1";
        String pwd = "335B725FTXcid";*/
        /*String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=SWTDB2";
        String user = "SWTDB2";
        String pwd = "335B725FTXcid";*/

        // 审计厅
        /*String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=sjt2_cms";
        String user = "shenjiting2";
        String pwd = "ddle1V2F+";*/

        // 濮阳
//        String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=puyang";
//        String user = "sa";
//        String pwd = "Dahe@2019";

        // 安阳公安局
//        String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=aygaj";
//        String user = "aygaj";
//        String pwd = "v1Vp2+FdpV2";

        // 教育厅
        /*String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=Hadoe_CMS2018";
        String user = "jyt1";
        String pwd = "4ycp_hnkjt2x";*/

        // 安阳市殷都区
        /*String url = "jdbc:sqlserver://10.10.10.233:1433;databaseName=ayydqzf";
        String user = "ayydqzf";
        String pwd = "4ycpv1V2F+";*/

        // 濮阳人民政府最新数据
/*        String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=puyang1";
        String user = "puyang1";
        String pwd = "335B725FTXcid";*/

        // 安阳市高新区
     /*   String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=aygxq";
        String user = "aygxq";
        String pwd = "dffwv1V231";*/
        //信阳市浉河区
        String url = "jdbc:sqlserver://10.10.10.249:1433;databaseName=shihewww";
        String user = "shihewww";
        String pwd = "335B725FTXcid";

        String initSize = "5";
        String maxSize = "60000";
        //创建连接池
        ds = new BasicDataSource();
        //设置参数
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(pwd);
        ds.setInitialSize(new Integer(initSize));
        ds.setMaxActive(new Integer(maxSize));
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

    public static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new RuntimeException("关闭连接失败", e);
            }
        }
    }


}
